import { Toast } from "vant"
import {CartAdd} from "../api/common"
import {StoreAll} from "../api/common"
let cartStore = {
    namespaced:true,
    state:{
        cartList:[],
        cartinfo:{
            user_id: 0,
            shop_id: 0,
            goods_id: 0,
            sku_id: "",
            goods_num: 1,
            active_type: 0,
        },
        shopinfo:{
            user_id: 0,
            shop_id: 0,
            sku_id: "",
            
        }
    },
    mutations:{
        getGoodsinfo(state,params){
            console.log("获取商品信息",params)
            state.cartinfo.user_id = params.user_id
            state.shopinfo.user_id = params.user_id
            state.cartinfo.shop_id = params.shop_id
            state.shopinfo.shop_id = params.shop_id
            state.cartinfo.goods_id = params.goods_id
            state.cartinfo.sku_id = params.sku_id
            state.shopinfo.sku_id = params.sku_id
            state.cartinfo.goods_num = params.goods_num
            state.cartinfo.active_type = params.active_type
        },
        addCartlist(state){
            CartAdd(state.cartinfo).then(res=>{
                console.log(res)
                if(res.code == 200){
                    console.log(1)
                    Toast.success('加入成功')
                }else{
                    Toast.fail('加入失败')
                }
            })
        },
        storeall(state,isall){
            state.shopinfo[shop_all] = isall
            StoreAll(state.shopinfo).then(res=>{
                console.log(res)
            })
        }
    },
    actions:{
        getGoodsInfo({commit},params){
            commit('getGoodsinfo',params)
        },
        addCartList({commit}){
            commit("addCartlist")
            // return Promise.resolve("")
        }
    },
    getters:{
        cartList:state=>state.cartList
    }
}

export default cartStore